/**
 * File		: Vector3.java
 * Subject	: Represents a vector with three coordinates
 * Author	: Isaac Parenteau (locus2k@gmail.com)
 * Date		: May 3rd, 2011
 */
package opengameflow.framework.vector;

public class Vector3 {

	private float x;
	private float y;
	private float z;
	
	/**
	 * Default Constructor
	 */
	public Vector3(){
		this(0,0,0);
	}

	/**
	 * Constructor
	 * @param x X coordinate
	 * @param y Y coordinate
	 * @param z Z coordinate
	 */
	public Vector3(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.y = z;
	}
	
	/**
	 * Gets the distance between two vectors
	 * @param other 
	 * @return distance between the vectors
	 */
	public float distance(Vector3 other){
		float xDif = this.x - other.getX();
		float yDif = this.y - other.getY();
		float zDif = this.z - other.getZ();
		
		xDif *= xDif;
		yDif *= yDif;
		zDif *= zDif;
		
		float distance = (float) Math.sqrt(xDif + yDif + zDif);
		
		return distance;
	}
	
	/**
	 * Normalizes the vector to a unit vector
	 * @param other other vector to normalize between
	 * @return normalized vector
	 */
	public Vector3 normalize(Vector3 other){
		float distance = distance(other);
		
		float xDist = this.x / distance;
		float yDist = this.y / distance;
		float zDist = this.z / distance;
		
		return new Vector3(xDist, yDist, zDist);
	}
	
	/**
	 * Adds a vector to the current vector and returns 
	 * a new vector with the added values
	 * @param other other vector to add
	 * @return new vector3 with the other values
	 */
	public Vector3 add(Vector3 other){
		return new Vector3(this.x + other.getX(),
				this.y + other.getY(), this.z + other.getZ());
	}
	
	/**
	 * Adds another vector to the current vector
	 * @param other other vector to add
	 */
	public void addVector(Vector3 other){
		this.x += other.getX();
		this.y += other.getY();
		this.z += other.getZ();
	}
	
	public boolean equals(Vector3 other) {
		return false;
	}
	
	public float getX() { return this.x; }
	public void setX(float x) { this.x = x; }
	public float getY() { return this.y; }
	public void setY(float y) { this.y = y; }
	public float getZ() { return this.z; }
	public void setZ(float z) { this.z = z; }
	
	public static Vector3 Up = new Vector3(0,1,0);
	public static Vector3 Zero = new Vector3(0,0,0);
}
